package com.eloisa.gls.web.controller;


import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.eloisa.gls.domain.CheckIn;
import com.eloisa.gls.domain.User;
import com.eloisa.gls.service.IUserContentService;

@Controller
@RequestMapping("/userContent")
public class UserContentController {
	@Autowired
	private IUserContentService service;
	
	@RequestMapping(value="login" ,method=RequestMethod.GET)
	public @ResponseBody Map login(@RequestParam String account, @RequestParam String uuid){
		User user = service.getUser(account, uuid);
		Map<String,Object> map = new HashMap<String,Object>();
		if(user != null && user.getId() != null){
			map.put("id", user.getId());
			return map;
		}else{
			map.put("id", "0");
			return map;
		}
	}
	
	@RequestMapping(value="checkIn" ,method=RequestMethod.GET)
	public @ResponseBody Map checkIn(@RequestParam Integer userId, @RequestParam Integer lessonId){
		Map<String,Object> map = new HashMap<String,Object>();
		try {
			CheckIn checkIn = new CheckIn();
			checkIn.setUserId(userId);
			checkIn.setLessonId(lessonId);
			checkIn.setCheckInTime(new Date());
			service.createCheckIn(checkIn);
			map.put("result", "1");
			return map;
		} catch (Exception e) {
			e.printStackTrace();
			map.put("result", "0");
			return map;
		}
	}
	
}
